package com.taru.wxhsh.api;

import com.taru.wxhsh.common.JsonResult;
import com.taru.wxhsh.constant.JResponseConstants;
import com.taru.wxhsh.pojo.Category;
import com.taru.wxhsh.service.CategoryService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@CrossOrigin
public class CategoryApi {
    Logger logger  = LoggerFactory.getLogger(CategoryApi.class);
    @Autowired
    CategoryService categoryService;

    /**
     * 查询类别列表
     * @return
     */
    @ResponseBody
    @RequestMapping("/api/category/list")
    public Object qryList(){
        JsonResult<List<Category>> result = null;
        try {
            List<Category> list = categoryService.qryList();
            result = new JsonResult<List<Category>>(JResponseConstants.STATUS_OK,"查询类别成功",list);
        }catch (Exception ex){
            logger.error("查询类别异常：{}",ex.getMessage());
            result = new JsonResult<List<Category>>(JResponseConstants.STATUS_ERROR,"查询类别异常");
        }

        return  result;
    }


}
